using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.XPath;
using System.Xml;

namespace EventAbstractionAPI.ApplicationObjectModel
{
    public class myTreeNodeClass : ICloneable, IXPathNavigable, IXmlNamespaceResolver
    {
        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="key">The nodes xpath name</param>
        internal myTreeNodeClass(String name, Object dataObject, myTreeNodeClass parent)
        {
            _key = name;
            _dataObject = dataObject;
            _parentNode = parent;
        }

        #endregion

        #region Properties

        public String name
        {
            get { return _key; }
        }

        public Object value
        {
            get { return _dataObject; }
        }

        public myTreeNodeClass Parent
        {
            get { return _parentNode; }
            set { _parentNode = value; }
        }

        public LinkedList<myTreeNodeClass> Children
        {
            get { return _childNodes; }
            set { _childNodes = value; }
        }

        public myTreeNodeClass FirstChild
        {
            get { return _childNodes.First.Value; }
        } 

        #endregion

        #region IXPathNavigable Members

        public XPathNavigator CreateNavigator()
        {
            XPathNavigator xnav = new XPathNav(this);
            return xnav;
        }

        public XPathNodeType NodeType
        {
            get
            {
                if (_parentNode == null)
                {
                    return XPathNodeType.Root;
                }
                else if (_childNodes.Count < 1)
                {
                    return XPathNodeType.Attribute;
                }
                else
                {
                    return XPathNodeType.Element;
                }
            }
        }

        #endregion

        #region IXmlNamespaceResolver Members

        public IDictionary<string, string> GetNamespacesInScope(XmlNamespaceScope scope)
        {
            throw new NotImplementedException();
        }

        public string LookupNamespace(string prefix)
        {
            throw new NotImplementedException();
        }

        public string LookupPrefix(string namespaceName)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region Member Variables

        private String _key;
        private Object _dataObject;

        private LinkedList<myTreeNodeClass> _childNodes = new LinkedList<myTreeNodeClass>();
        private myTreeNodeClass _parentNode = null; 

        #endregion
    }
}
